NDVI is the most widely used remote sensing index to quantify vegetation greenness,
health, and density based on the contrast between red and near-infrared reflectance.
1. Scientific Definition
The Normalized Difference Vegetation Index (NDVI) is a spectral index
that expresses the relative difference between Near-InfraRed (NIR) and Red reflectance
to highlight green vegetation. Healthy vegetation absorbs most of the red light
(for photosynthesis) and strongly reflects NIR.
Use surface reflectance products (e.g. COPERNICUS/S2_SR).
Filter by cloud percentage and date range.
Clip results to Area of Interest (AOI) before exporting.
Use consistent time windows when comparing multiple dates.
Palette Suggestion
A commonly used NDVI color palette:
[ "#440154", "#3b528b", "#21908c", "#5dc963", "#fde725" ]
3. Google Earth Engine Code – NDVI for Any AOI
Steps: open code.earthengine.google.com → New Script → paste the code →
draw your AOI as geometry on the map → click Run.
Then export NDVI as GeoTIFF to Google Drive.
// NDVI for any Area of Interest (AOI) using Sentinel-2 SR
// -------------------------------------------------------
// 1) Go to: https://code.earthengine.google.com
// 2) Click "New Script" and paste this code.
// 3) On the map: draw your AOI (Polygon/Rectangle).
// It will appear as a variable named 'geometry' in the left panel.
// 4) Click "Run" to display NDVI.
// 5) In the Tasks tab, click "Run" to export NDVI to Google Drive.
// -------------------------------------------------------
// 1. Define Area of Interest (AOI)
// -------------------------------------------------------
// Use the geometry you draw on the map:
var roi = geometry; // Make sure a 'geometry' object exists in the left panel
// Center the map on the AOI
Map.centerObject(roi, 11);
// -------------------------------------------------------
// 2. Define time range
// Adjust dates according to your study period
// -------------------------------------------------------
var startDate = '2023-01-01';
var endDate = '2023-12-31';
// -------------------------------------------------------
// 3. Load Sentinel-2 Surface Reflectance collection
// and prepare a homogeneous ImageCollection
// -------------------------------------------------------
var s2 = ee.ImageCollection('COPERNICUS/S2_SR')
.filterBounds(roi)
.filterDate(startDate, endDate)
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
// keep only the bands needed to compute NDVI to avoid band mismatches
.select(['B4', 'B8']); // B4 = Red, B8 = NIR
// Create a median composite and clip to AOI
var image = s2.median().clip(roi);
// -------------------------------------------------------
// 4. Compute NDVI
// -------------------------------------------------------
// NDVI = (NIR - Red) / (NIR + Red)
var ndvi = image.normalizedDifference(['B8', 'B4']).rename('NDVI');
// -------------------------------------------------------
// 5. Visualization on the map
// -------------------------------------------------------
var ndviVis = {
min: -1,
max: 1,
palette: [
'#440154', // low (water / no vegetation)
'#3b528b',
'#21908c',
'#5dc963',
'#fde725' // high (dense healthy vegetation)
]
};
// Add NDVI layer to the map
Map.addLayer(ndvi, ndviVis, 'NDVI (Sentinel-2)', true);
// Optionally, also show a true color composite for context
var s2_rgb = ee.ImageCollection('COPERNICUS/S2_SR')
.filterBounds(roi)
.filterDate(startDate, endDate)
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
.select(['B4','B3','B2']) // RGB
.median()
.clip(roi);
Map.addLayer(s2_rgb, {min:0, max:3000}, 'True Color (RGB)', false);
// -------------------------------------------------------
// 6. Export NDVI as GeoTIFF to Google Drive
// -------------------------------------------------------
Export.image.toDrive({
image: ndvi,
description: 'NDVI_Export',
fileNamePrefix: 'NDVI_Export',
region: roi,
scale: 10, // Sentinel-2 native resolution for B8/B4
crs: 'EPSG:4326',
maxPixels: 1e13
});
// End of script